package com.dhc.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhc.service.entity.Academy;
import com.dhc.service.entity.Profession;
import com.dhc.service.entity.vo.AcademyProfessionVo;
import com.dhc.service.entity.vo.ProfessionVo;
import com.dhc.service.mapper.AcademyMapper;
import com.dhc.service.mapper.ProfessionMapper;
import com.dhc.service.service.AcademyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Administrator
 * @description 针对表【ACADEMY(学院表)】的数据库操作Service实现
 * @createDate 2023-10-09 10:39:24
 */
@Service
public class AcademyServiceImpl extends ServiceImpl<AcademyMapper, Academy>
		implements AcademyService {

	@Autowired
	private AcademyMapper academyMapper;

	@Autowired
	private ProfessionMapper professionMapper;

	@Override
	public List<AcademyProfessionVo> queryAll() {
		List<Academy> academyList = academyMapper.selectList(null);
		return academyList.stream().map(academy -> {
			Long acaId = academy.getAcaId();
			QueryWrapper<Profession> wrapper = new QueryWrapper<>();
			wrapper.eq("PRO_ACA_ID", acaId);
			List<Profession> professionList = professionMapper.selectList(wrapper);
			List<ProfessionVo> professionVoList = professionList.stream().map(profession -> {
				ProfessionVo professionVo = new ProfessionVo();
				BeanUtils.copyProperties(profession, professionVo);
				return professionVo;
			}).collect(Collectors.toList());
			AcademyProfessionVo academyProfessionVo = new AcademyProfessionVo();
			academyProfessionVo.setAcaId(academy.getAcaId());
			academyProfessionVo.setAcaName(academy.getAcaName());
			academyProfessionVo.setCreateTime(academy.getCreateTime());
			academyProfessionVo.setProfessionVoList(professionVoList);
			return academyProfessionVo;
		}).collect(Collectors.toList());
	}
}




